package com.github.postsanf.yinian.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.github.postsanf.yinian.BaseActivity;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.ZoomBigAdapter;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.view.MultiTouchViewPager;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;

public class ImageLocalEditZoomBigActivity extends BaseActivity implements ZoomBigAdapter.Callback {
    private MultiTouchViewPager vp_zoombig_image;
    private ZoomBigAdapter mAdapter;
    private ArrayList<String> picUrlsList = new ArrayList<>();
    private int position = 0;
    long fristtime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fristtime = System.currentTimeMillis();
        registerBoradcastReceiver();
        setContentView(R.layout.yn_imagelocaledit_zoombig);
        initData();
        initView();
        initViewPager();
    }

    // 广播接收
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            switch (action) {
                case ACTIONs.actionCloseAlbum:
                    int noClear = intent.getExtras().getInt(ACTIONs.aIsClearSelect);
                    if (1 == noClear) {
                        finish();
                    }
                    break;
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.unregisterReceiver(mBroadcastReceiver);
    }

    //注册广播
    private void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(ACTIONs.actionCloseAlbum);
        this.registerReceiver(mBroadcastReceiver, myIntentFilter);
    }

    private void initData() {
        picUrlsList = getIntent().getStringArrayListExtra("picUrlsList");
        position = getIntent().getIntExtra("position", 0);
    }

    private void initView() {
        vp_zoombig_image = (MultiTouchViewPager) findViewById(R.id.vp_zoombig_image);
    }


//    @Override
//    public void click(View v) {
//        long pathftime = System.currentTimeMillis() - fristtime;
//        Log.i("xjs", "pathftime==>" + pathftime);
//        if (pathftime < 500) {
//            finish();
//        }
//        if (!tOPShow) {
//            rl_zoombig_top.setVisibility(View.GONE);
//            rl_zoombig_buttom.setVisibility(View.GONE);
//            tOPShow = true;
//        } else {
//            rl_zoombig_top.setVisibility(View.VISIBLE);
//            rl_zoombig_buttom.setVisibility(View.VISIBLE);
//            tOPShow = false;
//        }
//    }

    @Override
    public void onPhotoTap(View view, float x, float y) {
        Log.i("xjs", "onPhotoTap");
        finish();
//        if (!tOPShow) {
//            rl_zoombig_top.setVisibility(View.GONE);
//            rl_zoombig_buttom.setVisibility(View.GONE);
//            tOPShow = true;
//        } else {
//            rl_zoombig_top.setVisibility(View.VISIBLE);
//            rl_zoombig_buttom.setVisibility(View.VISIBLE);
//            tOPShow = false;
//        }
    }

    private void initViewPager() {
        mAdapter = new ZoomBigAdapter(this, picUrlsList, this);
        vp_zoombig_image.setAdapter(mAdapter);
        vp_zoombig_image.setCurrentItem(position);
    }


    // 友盟统计
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }
}
